home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / geometer / geom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  7.5 KB  |  221 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. #include <stdio.h>
  19.  
  20. extern long layerset, currentcolor;
  21.  
  22. #define TOL         (pbsize/1.0)
  23. #define NAMELENGTH  30
  24. #define UIWIDTH    230
  25. #define INVISIBLE   -1
  26. #define SMEAR        -2
  27. #define BLINK        -3
  28.  
  29. enum constrainttype {
  30.     NULLCONSTRAINT, 
  31.     VERTFREE,           // no constraints -- 2 degrees of freedom
  32.     VERTONLINE,         // vertex lies on line -- 1 D.O.F
  33.     VERTONCIRCLE,       // vertex on circle -- 1 D.O.F
  34.     VERTDISTFROMLINE,   // vertex a given distance from a line -- 1 D.O.F
  35.     VERTLINELINE,       // on intersection of 2 lines
  36.     VERTLINECIRC1,      // on intersection of line, circle
  37.     VERTLINECIRC2,      // on intersection of line, circle
  38.     VERTCIRCCIRC1,         // on circle/circle intersection
  39.     VERTCIRCCIRC2,         // on circle/circle intersection
  40.     VERTCIRCCENTER,     // vertex is circle's center
  41.     VERTVERTVERTMID,     // vertex is midpoint
  42.     VERTLINEVERTMIRROR, // vertex is mirror image through line
  43.     VERTCIRCVERTINV,    // invert a vertex through a circle
  44.     LINEVERTVERT,       // line through 2 vertices
  45.     LINEVERTLINEPAR,    // line through vertex; parallel to line
  46.     LINEVERTLINEPERP,   // line through vertex; prependicular to line
  47.     LINEVERTCIRC1,      // through vertex; tangent to circle
  48.     LINEVERTCIRC2,      // through vertex; tangent to circle
  49.     LINELINEPERPCIRC,   // perpendicular to line; tangent to circle
  50.     LINELINEPARCIRC,    // parallel to line; tangent to circle
  51.     LINECIRCCIRCEXT1,   // external tangent to 2 circles
  52.     LINECIRCCIRCEXT2,   // external tangent to 2 circles
  53.     LINECIRCCIRCINT1,   // external tangent to 2 circles
  54.     LINECIRCCIRCINT2,   // external tangent to 2 circles
  55.     CIRCVERTCIRC,       // circle through vertex; tangent to circle
  56.     CIRCVERTLINE,       // through vertex, tangent to line
  57.     CIRCVERTVERT,       // through vertex, passing through another
  58.     CIRCVERTDIST,       // center at vertex, radius = distance
  59.     CIRCVERTVERTVERT,   // circle through 3 vertices
  60.     CIRCLINELINELINE1,   // tangent to 3 lines
  61.     CIRCLINELINELINE2,   // tangent to 3 lines
  62.     CIRCLINELINELINE3,   // tangent to 3 lines
  63.     CIRCLINELINELINE4,   // tangent to 3 lines
  64.     CIRCCIRCCIRCCIRC,   // tangent to 3 circles
  65.     CIRCVERTVERTLINE,   // through 2 vertices; tangent to line
  66.     CIRCVERTVERTCIRC,   // through 2 vertices; tangent to circle
  67.     CIRCLINELINEVERT,   // tangent to 2 lines; through vertex
  68.     CIRCLINELINECIRC,   // tangent to 2 lines and a circle
  69.     CIRCCIRCCIRCVERT,   // tangent to 2 circles and through vertex
  70.     CIRCCIRCCIRCLINE,   // tangent to 2 circles and a line
  71.     CIRCVERTLINECIRC,   // through a vertex; tangent to a line and circle
  72.     CIRCCIRCCIRCINV,     // invert a circle through another
  73.     CIRCLINECIRCINV,     // invert a line through a circle
  74.     BEZVERTVERTVERTVERT, 
  75.     BSPVERTVERTVERTVERT,
  76.     RATIOVERTVERTVERT,
  77.     VERTVERTVERTRATIO, 
  78.     LENVERTVERT, 
  79.     CIRCVERTLEN, 
  80.     LENPLUSLENLEN, 
  81.     LENMINUSLENLEN, 
  82.     ANGLEVERTVERTVERT, 
  83.     VERTANGLEVERTVERT, 
  84.     ANGLEANGLETRISECT,     // angle = angle/3
  85.     ANGLEANGLELEN,         // angle = angle*float
  86.     ANGLEFLOAT,         // angle = float
  87.     LENFLOAT,            // len = float
  88.     LENTIMESLENLEN, 
  89.     LENDIVLENLEN,
  90.     CONICFIVEVERT,      // conic from 5 vertices
  91.     VERTONCONIC,
  92.     LINETANGENTCONIC1,
  93.     LINETANGENTCONIC2, 
  94.     CONICFIVELINE,      // conic from 5 lines
  95.     VERTLINECONIC1, 
  96.     VERTLINECONIC2, 
  97.     LENANGLE, 
  98. };
  99.  
  100. class constraint {
  101. public:
  102.     constrainttype      type;
  103.     class primitive     *p1, *p2, *p3, *p4, *p5;
  104. };
  105.  
  106. class primitive {
  107. public:
  108.     primitive   *next;
  109. //    char        iname[NAMELENGTH];
  110.     char        name[NAMELENGTH];
  111.     struct symtableentry *st;
  112.     constraint  c;
  113.     long        satisfied;  // constraint c is satisfied
  114.     long        Color;
  115.     long        layers;
  116.     reservedword    ptype;
  117.     primitive() { next = (primitive *)0; name[0] = (char)0;
  118.                     c.p1 = c.p2 = c.p3 = c.p4 = c.p5 = (primitive *)0; 
  119.             Color = (currentcolor== -1)?7:currentcolor;
  120.             satisfied = 0; layers = layerset; }
  121. };
  122.  
  123. class vertex : public primitive {
  124. public:
  125.     float               xw, yw, w;
  126.     void                draw();
  127.     void                PostScript(FILE *);
  128.     long                hitvertex(float, float);
  129.     void                projecttoline(class line *);
  130.     reservedword        type;
  131.     vertex()            { ptype = _vertex; xw = yw = 0.0; w = 1.0; type = _diamond; }
  132. };
  133.  
  134. // the ratio class is a ratio of distances --
  135. // (_ratio v1 v2 v3) == length(v1v2)/length(v1v3)
  136. // usually v2 is between v1 and v3
  137.  
  138. class length : public primitive {
  139. public:
  140.     float               value;
  141.     void                draw();
  142.     void                PostScript(FILE *);
  143.     length()             { ptype = _length; value = 0.5; }
  144. };
  145.  
  146. //class ratio : public primitive {
  147. //public:
  148. //    float               value;
  149. //    void                draw();
  150. //    void                PostScript(FILE *);
  151. //    ratio()             { ptype = _ratio; value = 0.5; }
  152. //};
  153.  
  154. //class angle : public primitive {
  155. //public:
  156. //    float               value;
  157. //    void                draw();
  158. //    void                PostScript(FILE *);
  159. //    angle()             { ptype = _angle; value = 1.570796326; }
  160. //};
  161.  
  162. class comment : public primitive {
  163. public:
  164.     char               str[150];
  165.     void                draw();
  166.     void                PostScript(FILE *);
  167.     comment()             { ptype = _comment; str[0] = (char)0; }
  168. };
  169.  
  170. class text : public primitive {
  171. public:
  172.     char               str[150];
  173.     void                draw();
  174.     void                PostScript(FILE *);
  175.     text()             { ptype = _text; str[0] = (char)0; }
  176. };
  177.  
  178. class line : public primitive {
  179. public:
  180.     vertex              v1, v2;
  181.     float               XW, YW, W;
  182.     reservedword        type;
  183.     void                draw();
  184.     void                PostScript(FILE *);
  185.     long                hitline(float, float);
  186.     float               disttoline(float, float);
  187.     line()              { ptype = _line; type = _segment; v1.w = 0.0; }
  188. };
  189.  
  190. class bezier : public primitive {
  191. public:
  192.     vertex              v1, v2, v3, v4;
  193.     void                draw();
  194.     void                PostScript(FILE *);
  195.     long                hitbezier(float, float);
  196.     float               disttobezier(float, float);
  197.     bezier()            { ptype = _bezier; v1.w = 0.0; }
  198. };
  199.  
  200. class circle : public primitive {
  201. public:
  202.     vertex              center;
  203.     float               radius;
  204.     vertex              v1, v2, v3;
  205.     void                draw();
  206.     void                PostScript(FILE *);
  207.     long                hitcircle(float, float);
  208.     float               disttocircle(float, float);
  209.     circle()            { ptype = _circle; center.w = 0.0; }
  210. };
  211.  
  212. class conic : public primitive {
  213. public:
  214.     double               aa, bb, cc, dd, ee, ff;
  215.     void                draw();
  216.     void                PostScript(FILE *);
  217.     long                hitconic(float, float);
  218.     float               disttoconic(float, float);
  219.     conic()            { ptype = _conic; }
  220. };
  221.